import java.util.LinkedList;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class MyStack<T> {

    LinkedList<T> linkedList = new LinkedList<>();

    public synchronized  void push(T t) {
        while (linkedList.size() >= 200) {
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        linkedList.addLast(t);
        this.notify();
    }
    public synchronized T pull( ){
        while(linkedList.isEmpty()){
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        this.notifyAll();
        return linkedList.removeLast();
        
    }
}
